<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="auth" uri="auth"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link rel="stylesheet" href="${ctx}/css/common.css" />
<link rel="stylesheet" href="${ctx}/css/pagination.css" />
<link rel="stylesheet" href="${ctx}/css/dialog/skin/bluebar/ymPrompt.css" />

<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery.pagination.js"></script>
<script type="text/javascript" src="${ctx}/js/dialog/ymPrompt.js"></script>

<script language="javascript">
var pageIndex = 0;
var pageSize = 10;

$(document).ready(function() {
    //分页
    InitTable(0);
    
    $("#page").pagination(${backupCount}, {
            callback: pageCallback,  
            prev_text: '<s:text name="PrePage" />',       //上一页按钮里text  
            next_text: '<s:text name="NextPage" />',       //下一页按钮里text  
            items_per_page: pageSize,  //显示条数  
            num_display_entries: 6,    //连续分页主体部分分页条目数  
            current_page: pageIndex,   //当前页索引  
            num_edge_entries: 2        //两侧首尾分页条目数  
    });
    
    //翻页调用  
    function pageCallback(index,jq) {
    	InitTable(index);
    }
    
    //初始化表格
    function InitTable(pageIndex) {
    	top.showProgress("<s:text name='LoadingAppData' />....");
    	
    	var ajaxUrl = '../ajax/getBackUpByPage.action?page='+pageIndex+'&pageSize='+pageSize;     //提交到一般处理程序请求数据

    	$("#dataList tbody").html("");
        
        $.getJSON(ajaxUrl,function(data){
        	html = "";
        	
        	if(data == null || data.length == 0){
        		html += "<tr>\r\n"+
							"<td height='40' colspan='4' class='td_content'><s:text name='HasNoBackupData' /></td>\r\n"+
						"</tr>\r\n";
        	} else {
        		$.each(data,function(id,value){
                	html += "<tr onmouseover=\"this.style.background='#F2F2F2'\" onmouseout=\"this.style.background='#EEF7FD'\">\r\n"+
		                	"<td class=\"td_content\">"+value.fileName+"</td>"+
		                    "<td class=\"td_content\">"+value.backUpTime+"</td>";
		                    
		            
        			html += "<td class=\"td_content\">"+
        					"<auth:entity entityCode='RESTORE_DATA'><a href=\"javascript:restoreData(\'"+value.fileName+"\')\"><s:text name='RestoreData' /></a> ｜ </auth:entity>"+
        					"<auth:entity entityCode='DELETE_BACKUP'><a href=\"javascript:del(\'"+value.fileName+"\');\"><s:text name='DeleteBackUp' /></a></auth:entity></td>\r\n"+
        			   		"</tr>\r\n";
                });
        	}
        	
    		$("#dataList tbody").append(html);
    		top.hideProgress();
        });                  
    }
});

function del(fileName){
	parent.ymPrompt.confirmInfo("<s:text name='ConfirmToDeleteThisFile' />？",null,
			null,null,
			function(tp){
				if(tp=="ok"){
					top.showProgress("<s:text name='Restoring' />....");
					var ajaxUrl = "../ajax/removeBackupFile.action?fileName="+fileName;
					$.getJSON(ajaxUrl,function(data){
						top.hideProgress();
						if(data){
							ymPrompt.succeedInfo("<s:text name='RemoveFileSuccess' />！",null,null,null,refresh);
						} else {
							ymPrompt.succeedInfo("<s:text name='RemoveFileFails' />！",null,null,null,refresh);
						}
					});
				}
			}
	);
}

function backUpData(){
	top.showProgress("<s:text name='DataBackuping' />....");
	var ajaxUrl = "../ajax/dataBackup.action";
	$.getJSON(ajaxUrl,function(data){
		top.hideProgress();
		if(data){
			ymPrompt.succeedInfo("<s:text name='DataBackupSuccess' />！",null,null,null,refresh);
		} else {
			ymPrompt.succeedInfo("<s:text name='DataBackupFails' />！",null,null,null,refresh);
		}
	});
}

function restoreData(fileName){
	parent.ymPrompt.confirmInfo("<s:text name='ConfirmToRestoreData' />？",null,
			null,null,
			function(tp){
				if(tp=="ok"){
					top.showProgress("<s:text name='Restoring' />....");
					var ajaxUrl = "../ajax/restoreData.action?fileName="+fileName;
					$.getJSON(ajaxUrl,function(data){
						top.hideProgress();
						if(data){
							ymPrompt.succeedInfo("<s:text name='RestoreDataSuccess' />！",null,null,null,refresh);
						} else {
							ymPrompt.succeedInfo("<s:text name='RestoreDataFails' />！",null,null,null,refresh);
						}
					});
				}
			}
	);
}

//刷新页面
function refresh(tp){
	if(tp=="ok"){
		$("#mainFrame",window.parent.document).attr("src","dataBackUpPage.action");
	}
}
</script>

</head>

<body>
	<div class="table_header">
		<auth:entity entityCode='BACKUP_DATA'>
    	<a href="javascript:backUpData();">
    		<span class="create_btn"><s:text name="DataBackup" /></span>
        </a>
        </auth:entity>
    </div>
	<table id="dataList" width="100%" cellspacing="1" cellpadding="5" class="table_class">
    	<thead>
        	<tr>
            	<td class="td_header" width="60%"><s:text name="FileName" /></td>
                <td class="td_header" width="20%"><s:text name="BackUpTime" /></td>
                <td class="td_header"><s:text name="Operate" /></td>
            </tr>
        </thead>
        <tbody>
        </tbody>
        <tfoot>
	        <tr>
				<td colspan="4" class="td_content">
					<div id="page" class="pagination"></div>
				</td>
			</tr>
        </tfoot>
    </table>
</body>
</html>
